package com.example.is432_teamlondon_2013;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
//import android.view.Menu;
import android.content.pm.ActivityInfo;

public class SplashActivity extends Activity {
	
    private Thread splashTread;
	
    @Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

	    final SplashActivity sPlashScreen = this; 
        
        // thread for displaying the SplashScreen
        splashTread = new Thread() {
            @Override
            public void run() {
                try {   
                		if ( isNetworkConnected() == true){
                			finish();
                        	Intent i = new Intent();
                        	i.setClass(sPlashScreen, MainActivity.class);
                        	startActivity(i);
                		} else{
                			finish();
                		}
                	
               } catch(Exception e) {
            	   
               } 
                
                    
                
            }
        };
        
        splashTread.start();
	}
    private boolean isNetworkConnected() {
    	  ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    	  NetworkInfo ni = cm.getActiveNetworkInfo();
    	  if (ni == null) {
    	   // There are no active networks.
    	   return false;
    	  } else
    	   return true;
    	 }
    /*
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.splash, menu);
		return true;
	}
	*/

}
